package com.lxq.smartsign.client.util;

import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.TextView;

import androidx.annotation.NonNull;
import androidx.recyclerview.widget.RecyclerView;

import com.lxq.smartsign.client.R;

import org.json.JSONObject;

import java.util.List;

public class BluetoothListAdapter extends RecyclerView.Adapter<BluetoothListAdapter.ItemViewHold> {

    List<JSONObject> bluetoothArray;

    public BluetoothListAdapter(List<JSONObject> bluetoothArray){
        this.bluetoothArray=bluetoothArray;
    }

    @NonNull
    @Override
    public ItemViewHold onCreateViewHolder(@NonNull ViewGroup parent, int viewType) {
        return new ItemViewHold(LayoutInflater.from(parent.getContext()).inflate(R.layout.item_bluetooth,null));
    }

    @Override
    public void onBindViewHolder(@NonNull ItemViewHold holder, int position) {
        JSONObject item=bluetoothArray.get(position);
        holder.name.setText(item.optString("name"));
        holder.address.setText(item.optString("address"));
    }

    @Override
    public int getItemCount() {
        return bluetoothArray.size();
    }

    class ItemViewHold extends RecyclerView.ViewHolder {

        TextView name;
        TextView address;
        public ItemViewHold(@NonNull View itemView) {
            super(itemView);
            name=itemView.findViewById(R.id.item_bluetooth_name);
            address=itemView.findViewById(R.id.item_bluetooth_address);
        }
    }
}
